package com.study.thread;

import java.util.concurrent.*;

public class Thread3 implements Callable {
    @Override
    public String call() throws Exception {
        System.out.println("run3...");
        return "success";
    }

    public static void main(String[] args) throws Exception{
        //第一种调用方式, 通过FutureTask
        Thread3 thread3=new Thread3();
        FutureTask futureTask=new FutureTask(thread3);
        Thread thread = new Thread(futureTask);
        thread.start();
        //get方法是属于阻塞方法
        System.out.println(futureTask.get());

        //第二种调用方式, 通过线程池, 本质上还是FutureTask
        ExecutorService executor = Executors.newFixedThreadPool(1);
        FutureTask future = (FutureTask) executor.submit(thread3);
        System.out.println(future.get());
    }
}
